#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    int longestArithSeqLength(vector<int> &nums)
    {
        unordered_map<int, int> dp;
        int maxNum = *max_element(nums.begin(), nums.end());
        int minNum = *min_element(nums.begin(), nums.end());
        int maxD = maxNum - minNum;
        int max_len = 0;
        for (int d = -maxD; d <= maxD; d++)
        {
            dp.clear();
            for (auto num : nums)
            {
                if (dp.find(num - d) != dp.end())
                {
                    dp[num] = max(dp[num], dp[num - d] + 1);
                    max_len = max(max_len, dp[num]);
                }
                if (dp.find(num) == dp.end())
                {
                    dp[num] = 1;
                }
            }
        }
        return max_len;
    }
};

int main()
{
    cout << "Code1027" << endl;
    Solution s;
    vector<int> nums = {9,4,7,2,10};
    cout << s.longestArithSeqLength(nums) << endl;
    return 0;
}